package spms.front.controller;

import java.util.Locale;

import javax.annotation.security.PermitAll;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.LocaleResolver;
import static org.springframework.web.servlet.i18n.SessionLocaleResolver.LOCALE_SESSION_ATTRIBUTE_NAME;

@Controller
public class LanguageController {
	
	/*@Autowired
    LocaleResolver localeResolver;
	
	@PermitAll
	@RequestMapping("setLanguage")
    @ResponseBody
    public void setLocale(HttpServletRequest request, HttpServletResponse response) {
		String lang = request.getParameter("lang");
		HttpSession session=request.getSession();
		Locale locale = null;
		if (lang == null) {
			locale = request.getLocale();
		} else if ("en_US".equals(lang)) {
			locale = Locale.US;
		} else if ("zh_CN".equals(lang)) {
			locale = Locale.CHINA;
		} else if ("zh_TW".equals(lang)) {
			locale = Locale.TAIWAN;
		}
		//其余的不正确的默认就是本地的语言
		else {
			locale = request.getLocale();
		}
		localeResolver.setLocale(request,response,locale);
		session.getAttribute(LOCALE_SESSION_ATTRIBUTE_NAME);
	}
	
	@RequestMapping("/getLanguage")
	@ResponseBody
	public Object getlocal(HttpServletRequest request, HttpServletResponse response){
		Locale lang = (Locale) request.getSession().getAttribute(LOCALE_SESSION_ATTRIBUTE_NAME);
		return lang;
	}*/
}
